package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@HttpInlet(Conn.INLET_GET_INS_PRICING)
public class SetNewInsSUP extends JTAsyGet<SetNewInsSUP.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String userId = JTApplication.jtPreferences.readUserID();

    public String flag = "3";

    public SetNewInsSUP(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        info.ins_id = head.optString("sxId");

        JSONObject body = apiTYF.optJSONObject("body");

        info.flag = body.optString("flag");

        info.delIntegralCount = body.optString("delIntegralCount");

        info.delCommonCount = body.optString("delCommonCount");

        BaoxianOrder baoxianOrder = new BaoxianOrder();

        JSONObject Orderobject = body.optJSONObject("baoxianOrder");

        baoxianOrder.out_type = Orderobject.optString("OUT_TYPE");

        baoxianOrder.recipients_phone = Orderobject.optString("RECIPIENTS_PHONE");

        baoxianOrder.recipients = Orderobject.optString("RECIPIENTS");

        baoxianOrder.vin = Orderobject.optString("VIN");

        baoxianOrder.year = Orderobject.optString("YEAR");

        baoxianOrder.phidcard = Orderobject.optString("PHIDCARD");

        baoxianOrder.engine = Orderobject.optString("ENGINE");

        baoxianOrder.year_limit = Orderobject.optString("YEAR_LIMIT");

        baoxianOrder.idcard = Orderobject.optString("IDCARD");

        baoxianOrder.phone = Orderobject.optString("PHONE");

        baoxianOrder.accept_address = Orderobject.optString("ACCEPT_ADDRESS");

        baoxianOrder.car_versions = Orderobject.optString("CAR_VERSIONS");

        baoxianOrder.car_xh = Orderobject.optString("CAR_XH");

        baoxianOrder.owner_name = Orderobject.optString("OWNER_NAME");

        baoxianOrder.phphone = Orderobject.optString("PHPHONE");

        baoxianOrder.car_band = Orderobject.optString("CAR_BAND");

        baoxianOrder.plate_num = Orderobject.optString("PLATENUMBER");

        baoxianOrder.email = Orderobject.optString("EMAIL");

        baoxianOrder.phemail = Orderobject.optString("PHEMAIL");

        baoxianOrder.engine_size = Orderobject.optString("ENGINE_SIZE");

        baoxianOrder.phname = Orderobject.optString("PHNAME");

        info.baoxianOrder = baoxianOrder;

        JSONArray ins_list  = body.optJSONArray("sxList");

        if(ins_list != null)

        for(int i = 0; i<ins_list.length();i++){

            InsItem item = new InsItem();

            JSONObject listItem = ins_list.optJSONObject(i);

            item.price = listItem.optString("PRICE");

            item.name = listItem.optString("NAME");

            item.type = listItem.optString("INSURANCE_TYPE");

            item.flag_price = listItem.optString("FLAGMONEY");

            item.num = listItem.optString("NUM");

            item.flag_mark = listItem.optString("FLAG");

            item.ins_amount = listItem.optString("BAOE");

            info.mInsItemList.add(item);

        }

        return info;
    }

    public static class Info implements Serializable{

        public String msg;

        public String ins_id;

        public String flag;

        public BaoxianOrder baoxianOrder;

        public List<InsItem> mInsItemList = new ArrayList<>();

        public String delIntegralCount,delCommonCount;


    }

    public static class BaoxianOrder implements Serializable {

        public String  out_type,recipients_phone,recipients,vin,year,phidcard,engine,year_limit,idcard,phone;

        public String accept_address,car_versions,car_xh,owner_name,phphone,car_band,plate_num,email;

        public String phemail,engine_size,phname;

    }

    public static class InsItem implements Serializable{

        public String price;

        public String name;

        public String type;

        public String flag_price;

        public String num;

        public String flag_mark;

        public String ins_amount;

    }
}
